<template>
	<view class="wrap">
		<view class="box">
			<view v-if="imgurl" class="imgwrap">
				<view class="delete" @click="fndelete">X</view>
				<image class="select" :src="imgurl"></image>
			</view>
			
			<view v-else class="select"  @click="fnchooseimg">
				<vs-icon type="icon-jiahao" size="50"></vs-icon>
			</view>
		
			<button v-if="imgurl==''" type="primary" @click="select" >分享</button>
			<button v-else type="primary" open-type="share">分享</button>
		</view>
	</view>
</template>

<script>
	import imgSelect from '../../compoments/img-select.vue'
	export default {
		components:{
			imgSelect
		},
		data() {
			return {
				imgurl:'',
				wkid:'',
				classname:''
			};
		},
		onLoad(option) {
			console.log(option)
			this.wkid=option.wkid
			this.classname=option.classname
		},
		onShareAppMessage() {
			return {
				title:this.classname?this.classname:"欢迎体验打卡学习",
				path: '/pages/src/addbanji/addbanji?wkid='+this.wkid,
				imageUrl:this.imgurl
			}
		},
		methods:{
			fndelete(){
				this.imgurl=''
			},
			select(){
				if(this.imgurl==''){
					console.log(888)
					this.$fun.toast('请选择一张图片！');
					return;
				}
			},
			fnchooseimg(){
				uni.chooseImage({
					count:1,
					success: (res) => {
						console.log(res)
						this.imgurl=res.tempFilePaths[0]
					},
					fail: () => {
						// #ifdef MP
						uni.getSetting({
							success: (res) => {
								let authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera'];
								if (!authStatus) {
									uni.showModal({
										title: '授权失败',
										content: 'Hello uni-app需要从您的相机或相册获取图片，请在设置界面打开相关权限',
										success: (res) => {
											if (res.confirm) {
												uni.openSetting()
											}
										}
									})
								}
							}
						})
						// #endif
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.wrap{
		height: 100%;
		display: flex;
		//align-items: center;
		justify-content: center;
		padding-top: 100px;
		//background-color: #007AFF;
		.box{
			width: 90%;
			
			.i-img{
				
				background: #15BB31;
			}
		}
	}
	.imgwrap{
		width: 150px;
		position: relative;
		//background-color: #007AFF;
		.delete{
			width: 30px;
			height: 30px;
			background-color:#adadad;
			font-size: 16px;
			color: #fff;
			border-radius: 100%;
			text-align: center;
			line-height: 30px;
			position: absolute;
			right: -10px;
			top: -10px;
		}
		
	}
	.select{
		width: 150px;
		height: 150px;
		border: 1px solid #adadad;
		color: #dadada;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 50px;
	}
</style>
